﻿#region license
//Copyright 2008 Ritesh Rao 

//Licensed under the Apache License, Version 2.0 (the "License"); 
//you may not use this file except in compliance with the License. 
//You may obtain a copy of the License at 

//http://www.apache.org/licenses/LICENSE-2.0 

//Unless required by applicable law or agreed to in writing, software 
//distributed under the License is distributed on an "AS IS" BASIS, 
//WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
//See the License for the specific language governing permissions and 
//limitations under the License. 
#endregion

using System;
using System.Collections.Generic;
using NCommon;

namespace Rhinestone.Domain
{
    /// <summary>
    /// A project for which work items are created.
    /// </summary>
    public class Project
    {
        #region fields
        private int _projectID;
        private IUser _owner;
        private ICollection<IUser> _members = new HashSet<IUser>();
        #endregion

        #region properties
        /// <summary>
        /// Gets the unique ID assigned to the project.
        /// </summary>
        /// <value>int. The unique ID assigned to the project.</value>
        public virtual int ProjectID
        {
            get {return _projectID;}
        }

        /// <summary>
        /// Gets or sets the user specified project code for the <see cref="Project"/> instance.
        /// </summary>
        /// <value>string. The user specified project code</value>
        public virtual string Code { get; set; }

        /// <summary>
        /// Gets or sets the name of the project.
        /// </summary>
        /// <value>string. The name of the project.</value>
        public virtual string Name { get; set; }

        /// <summary>
        /// Gets or sets a breif description about the project.
        /// </summary>
        /// <value>string. The breif description about the project.</value>
        public virtual string Description { get; set; }

        /// <summary>
        /// Gets a list of users that are memnbers of the project.
        /// </summary>
        /// <value>An <see cref="IEnumerable{T}"/> containing the list of users that are members of the project.</value>
        public virtual IEnumerable<IUser> Members
        {
            get {return _members;}
        }

        /// <summary>
        /// Gets a <see cref="IUser"/> that is the owner of the project.
        /// </summary>
        /// <value>The <see cref="IUser"/> that is the owner of the project.</value>
        public virtual IUser Owner
        {
            get { return _owner; }
            set
            {
                Guard.Against<ArgumentNullException>(value == null, "Cannot set a null IUser instance as the owner of a project.");
                _owner = value;
                AddMember(_owner);
            }
        } 
        #endregion

        #region methods
        /// <summary>
        /// Adds a user as a member of the <see cref="Project"/> instance.
        /// </summary>
        /// <param name="member">An <see cref="IUser"/> instance representing the user
        /// to add as a member of the project.</param>
        public void AddMember(IUser member)
        {
            Guard.Against<ArgumentNullException>(member == null, "Cannot add a null IUser instance ");
            _members.Add(member);
        } 
        #endregion
    }
}
